package com.zhengdongzulin.zuke.app.main.mine.waterAndElectricityMeter

import android.graphics.drawable.GradientDrawable
import com.lxj.androidktx.core.dp2px
import com.lxj.androidktx.core.getVM
import com.zhengdongzulin.zuke.R
import com.zhengdongzulin.zuke.base.BaseFragment
import com.zhengdongzulin.zuke.databinding.ZkFragmentWAEBinding

/**
 * 水电表
 */
class ZKWAEMFragment(var mType: Type) : BaseFragment<WAEMVm, ZkFragmentWAEBinding>() {

    enum class Type {
        WATER,
        ELECTRICITY
    }

    companion object {
        fun newInstance(type: Type) = ZKWAEMFragment(type)
    }

    override fun getLayoutResId(): Int = R.layout.zk_fragment_w_a_e

    override fun initVM(): WAEMVm = getVM(WAEMVm::class.java)

    override fun initView() {
        mView.contentView.setEnableRefresh(false)
        mView.statusView.showContent()
        mView.rlMsg.background = GradientDrawable().apply {
            colors = intArrayOf(
                resources.getColor(R.color.color_B31273f7),
                resources.getColor(R.color.color_1273f7)
            )
            gradientType = GradientDrawable.LINEAR_GRADIENT
            orientation = GradientDrawable.Orientation.BL_TR
            cornerRadius = dp2px(5.0F).toFloat()
        }
        mView.tvRecharge.background = GradientDrawable().apply {
            colors = intArrayOf(
                resources.getColor(R.color.color_B31273f7),
                resources.getColor(R.color.color_1273f7)
            )
            gradientType = GradientDrawable.LINEAR_GRADIENT
            orientation = GradientDrawable.Orientation.BL_TR
            cornerRadius = dp2px(5.0F).toFloat()
        }

        mView.rlMsgType.background = GradientDrawable().apply {
            setColor(resources.getColor(R.color.color_76DBA3))
            cornerRadii = floatArrayOf(
                dp2px(5.0F).toFloat(),
                dp2px(5.0F).toFloat(),
                0.0f,
                0.0f,
                dp2px(5.0F).toFloat(),
                dp2px(5.0F).toFloat(),
                0.0f,
                0.0f
            )
        }

        mView.tvMsgAddress.text =
            "${(activity as ZKWAEMActivity).mChangeHomeData.houseName}${(activity as ZKWAEMActivity).mChangeHomeData.houseNumber}"

        when (mType) {
            Type.WATER -> {
                mView.tvMsgType.text = "水"
                mView.ivMsgType.setImageDrawable(resources.getDrawable(R.drawable.image_bill_water))
                mView.tvMsgTip.text = "累计用水量（m³）"

                mView.tvTip1.text = "昨日水费（元）"
                mView.tvTip2.text = "昨日用水量（m³）"
                mView.tvTip3.text = "水费余额（元）"
                mView.tvTip4.text = "水量余额（m³）"

                mView.tvRecharge.text = "充值水费"

            }
            Type.ELECTRICITY -> {
                mView.tvMsgType.text = "电"
                mView.ivMsgType.setImageDrawable(resources.getDrawable(R.drawable.image_bill_shandian))
                mView.tvMsgTip.text = "累计用电量（千瓦·小时）"


                mView.tvTip1.text = "昨日电费（元）"
                mView.tvTip2.text = "昨日用电量（千瓦·小时）"
                mView.tvTip3.text = "电费余额（元）"
                mView.tvTip4.text = "电量余额（千瓦·小时）"

                mView.tvRecharge.text = "充值电费"
            }
        }
    }

    override fun initData() {
        getData()
    }

    override fun initListener() {

    }

    private fun getData() {
        if (mType == Type.WATER)
            mViewModel.billWater((activity as ZKWAEMActivity).mChangeHomeData.houseId)
        else
            mViewModel.billElectricity((activity as ZKWAEMActivity).mChangeHomeData.houseId)
    }

    override fun startObserve() {
//        mViewModel.bill_list.observe(this, androidx.lifecycle.Observer {
//            mView.statusView.showContent()
//        })
//        mViewModel.bill_list.state.observe(this, getObserver(mViewModel.bill_list))
    }

}